/**
 * Author: Shen Yanqiu
 * Date: 2018-02-28
 * Time: 13:56
 *
 */
import React from 'react';
import { Form, Input, Button, Row, Col } from 'antd';

const FormItem = Form.Item;

class FormBlock extends React.Component {
  render () {
    const {
      form: {
        validateFields,
        getFieldDecorator
      },
      labelText,
      nameText,
      submitHandler,
      submitLoading,
    } = this.props;
    const clickHandler = () => {
      validateFields((error, values) => {
        if (error) {
          return;
        }
        submitHandler(values, nameText);
      });
    };
    return (
      <Form>
        <FormItem label={labelText} labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
          {
            getFieldDecorator(nameText, {
              rules: [
                { required: true, message: `${labelText}不能为空` },
              ],
            })(<Input placeholder={`请输入${labelText}`} />)
          }
        </FormItem>
        <FormItem>
          <Row justify={"center"} type={"flex"}>
            <Col>
              <Button type={"primary"} onClick={clickHandler} loading={submitLoading}>确认提交</Button>
            </Col>
          </Row>
        </FormItem>
      </Form>
    );
  }
}
export default Form.create()(FormBlock);
